package behavior;

/**
 * Creates an abstract behavior which has only one method that is to 
 * get the next-step velocity of the moving entity
 */
import individual.MovingEntity;

import java.util.ArrayList;
import java.util.List;

import utilities.Vector;

public abstract class Behavior {
	
	/**
	 * The main model for updating a moving entity's velocity. Returns the
	 * new velocity based on the current entity's position and its neighbors
	 * @param current the current entity
	 * @param allMovingEntities all the entities in the surrounding
	 * @return the next step velocity for the current entity
	 */
	public abstract Vector getNextVelocity(MovingEntity current, List<MovingEntity> allMovingEntities);
	
	/**
	 * Get the list of moving entities with the specified type
	 * @param type the type of the moving entity
	 * @param allMovingEntities all the moving entities in the surrounding
	 * @return the list of moving entities with the specified type
	 */
	public List<?> getListOfType(String type, List<MovingEntity> allMovingEntities) {
		try {
			Class classType = Class.forName(type);
			ArrayList listOfTypes = new ArrayList();
			for (MovingEntity mEntity: allMovingEntities) {
				if (classType.isInstance(mEntity)) {
						listOfTypes.add(mEntity);
				}
			}
			return listOfTypes;	
		} catch (ClassNotFoundException e) {
			System.err.println(e);
		}
		return null;
	}
}
